<?php
/**
 * ===============================================
 * 版权所有 2019-2050 青岛铁锤科技有限公司，并保留所有权利。
 * 网站地址: http://www.huaxianling.com
 * ===============================================
 * Author: Rag Hu
 * Created Time: 2019/7/9 14:13
 * Modified Time: 2019/7/9 14:13
 * Version: 2.0
 */

namespace App\Modules\System\Controllers;


use App\Modules\System\Services\ConfigService;
use Flower\Core\Http\BaseController;
use Flower\Core\Repository\Exceptions\ValidatorException;
use Illuminate\Http\Request;

class ConfigController extends BaseController
{
    private $configService;

    public function  __construct(ConfigService $configService)
    {
        $this->configService  = $configService;
    }

    public function getConfig(Request $request)
    {
        try{
            $keyword = $request->input('keyword');
            $val = $this->configService->getConfig($keyword);

            return $this->display($val,'查询成功');
        }
        catch (ValidatorException $ex){
            $msg = array_values($ex->getMessageBag()->getMessages())[0][0];
            return $this->error($msg);
        }
    }

    public function getDictionary(Request $request)
    {
        try{
            $code = $request->input('code');
            $val = $this->configService->getDictionary($code);

            return $this->display($val,'查询成功');
        }
        catch (ValidatorException $ex){
            $msg = array_values($ex->getMessageBag()->getMessages())[0][0];
            return $this->error($msg);
        }
    }
}